package com.competition.system.service.impl;

import com.competition.system.dao.UserDao;
import com.competition.system.pojo.User;
import com.competition.system.service.AuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Optional;

/**
 * @author Lyq
 * @version 1.0
 * @create 2020/12/17 9:16
 */
@Service
public class AuthServiceImpl implements AuthService {

    @Autowired
    private UserDao userDao;

    @Override
    public User findUserByLogin(User user) {
        Optional<User> byAccount = userDao.findByAccount(user.getAccount());
        if (byAccount.isPresent()){
            Optional<User> optionalUser = userDao.findByAccountAndPasswordAndPower(user.getAccount(), user.getPassword(), user.getPower());
            if (optionalUser.isPresent()){
                return optionalUser.get();
            }
        }
        return null;
    }
}
